<script src="../js/jquery-1.6.2.min.js"></script>
<script src="../js/load.js"></script>
<script src="../js/url.js"></script>
<link rel="stylesheet" href="../css/style.css" />
<div class="header"><h1>OMAR ADMIN LOGIN</h1></div>

<center>
<div class="form_div">
<div class="well">
<div class="input_textbox">
<input type="text" id="username" name="username" placeholder="User Name"/><span id="errorMessage" name="errorMessage" style="color:red;"></span>
<input type="password" id="password" name="password" placeholder="Password"/><span id="errorpassMessage" name="errorpassMessage" style="color:red;"></span>
<div class="clear"></div>
<input type="button"  id="login" value="Login" onclick="loginInformation()">
<span id="error" name="error" style="color:red;"></span>
</div>
</div>
</div>
</center>

<script>
var adminemail	="admin@gmail.com";
var adminpassword	="admin";
function loginInformation(){
	var flag=true;
	var username=$('#username').val();
	var password=$('#password').val();
	
	if(username==""){
		$('#errorMessage').html("Required");
		flag=false;
	}else{
	    if(validateEmail(username)==0){
		  $("#errorMessage").html("Invalid Email");
		  flag=false; 
	    }else{
			$('#errorMessage').html("");
		}
	} 
	if(password==""){
		$('#errorpassMessage').html("Required");
		flag=false;
	}else{
		$('#errorpassMessage').html("");
	}
	if(flag==true){
		if(adminemail==username && adminpassword==password){
			sessionStorage.setItem( 'adminemail', JSON.stringify(adminemail));
				window.location="login.html";
		}else{
			$('#error').html("username/password is wrong.");
		}
	}
}
function validateEmail(emailValue){
var emailvalidation = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if(!emailvalidation.test(emailValue)){
     return 0;
    }else{
      return 1;
    }
}
$('#password').keypress(function(e){
	if( e.keyCode == 13 ){
		loginInformation();
		return false;
	}
});
</script>
